home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 2005 - 2006 Yahoo! Inc. All rights reserved.
- */
- function nsIYahooFeedProcessor(){}
- nsIYahooFeedProcessor.prototype = {
- NOT_LOADED : 0x01,
- CACHE_LOADED : 0x02,
- LIVE_LOADED : 0x03,
- feedVer : "4",
- clientVer : "1.0.0",
- clientID : null,
- country : "us",
- lang : "us",
- corp : "",
- partner : "",
- FEED_URL : "http:\/\/us.update2.toolbar.yahoo.com/slv/v4/2.html?&.pc=&t=1123627243899&.ta=cgnone,cc,cius,cv1_1_0,cp,cbm",
- loads : 0,
- loaded : false,
- loading : false,
- loadedType : this.NOT_LOADED,
- isGuest : true,
- cacheFile : null,
- raw : null,
- params : null,
- values : null,
- domBuilder : null,
- styles : { "std" : {
- 1 : "OUTLINE", 2 : "ROUNDEDGE", 4 : "HIGHLIGHT", 8 : "RAISED", 16 : "STATIC", 32 : "TOGGLE", 64 : "MODIFIABLE",
- 128 : "LOCAL", 256 : "NOMENUHIDE", 512 : "NOTEXT", 1024 : "NOMORE", 2048 : "REMOVEONCLICK", 4096 : "TOGGLEOFF",
- 8192 : "MINIMIZABLE", 16384 : "REDIRECT", 32768 : "MENUITEM", 65536 : "NOUSECACHE", 131072 : "NOTOOLTIP",
- 262144 : "ALWAYSPRESSED", 524288 : "ANIMATED", 1048576 : "ALWAYSHIDE", 2097152 : "BROWSERIMAGE"
- },
- "ext" : {
- 1 : "EX_ALIGNCENTER", 2 : "EX_ALIGNRIGHT", 4 : "EX_MODUSERES", 4 : "EX_MODUSERES", 8 : "EX_MODUSERPAR",
- 16 : "EX_TBLINEFEED", 32 : "EX_TBNOCLOSE", 64 : "EX_TBNOGETMOD", 128 : "EX_TBPASSEDIT", 256 : "EX_TBFORCEGETMOD",
- 8192 : "EX_ENABLEDBY", 65536 : "EX_ENABLEDBY", 131072 : "EX_NEWWINDOWTAB"
- }
- },
- loadingAlerts : false,
- code : [],
- charsets : [],
- notifier : null,
- stream : null,
- size : 0,
- timer : null,
- bm2timer : null,
- uniconvert : null,
- acs : null,
- init : function() {
- if(this.loaded == false){
- this.notifier = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- this.uniconvert = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
- this.uniconvert.charset = 'utf-8';
- this.params = Components.classes["@yahoo.com/feed/hashtable;1"].createInstance(Components.interfaces.nsIYahooHashtable);
- this.values = Components.classes["@yahoo.com/feed/hashtable;1"].createInstance(Components.interfaces.nsIYahooHashtable);
- this.domBuilder = Components.classes["@yahoo.com/dombuilder;1"].getService(Components.interfaces.nsIYahooDomBuilder);
- this.code[0x01] = String.fromCharCode(0x01);
- this.code[0x02] = String.fromCharCode(0x02);
- this.code[0x03] = String.fromCharCode(0x03);
- this.code[0x04] = String.fromCharCode(0x04);
- this.code[0x05] = String.fromCharCode(0x05);
- this.code[0x06] = String.fromCharCode(0x06);
- this.code[0x07] = String.fromCharCode(0x07);
- this.code[0x08] = String.fromCharCode(0x08);
- this.code[0x09] = String.fromCharCode(0x09);
- this.code[0x14] = String.fromCharCode(0x14);
- this.code[0x15] = String.fromCharCode(0x15);
- this.code[0x16] = String.fromCharCode(0x16);
- this.code[0x17] = String.fromCharCode(0x17);
- this.code[0x18] = String.fromCharCode(0x18);
- this.code[0x19] = String.fromCharCode(0x19);
- this.charsets[1] = 'iso-8859-1';
- this.charsets[128] = 'shift_jis';
- this.charsets[129] = 'euc-kr';
- this.charsets[130] = 'johab';
- this.charsets[134] = 'gb2312';
- this.charsets[136] = 'Big5';
- this.charsets[161] = 'windows-1253';
- this.charsets[162] = 'windows-1254';
- this.charsets[163] = 'windows-1258';
- this.charsets[177] = 'windows-1255';
- this.charsets[178] = 'windows-1256';
- this.charsets[186] = 'windows-1257';
- this.charsets[204] = 'windows-1251';
- this.charsets[222] = 'windows-874';
- this.charsets[238] = 'windows-1250';
- try{
- this.cacheFile = Components.classes["@mozilla.org/file/directory_service;1"].createInstance(Components.interfaces.nsIProperties);
- this.cacheFile = this.cacheFile.get("PrefD", Components.interfaces.nsILocalFile);
- this.cacheFile.appendRelativePath("extensions");
- this.cacheFile.appendRelativePath("{635abd67-4fe9-1b23-4f01-e679fa7484c1}");
- if(!this.cacheFile.exists()){
- this.cacheFile.create(Components.interfaces.nsILocalFile.DIRECTORY_TYPE, 0777);
- }
- this.cacheFile.appendRelativePath("cache");
- if(!this.cacheFile.exists()){
- this.cacheFile.create(extd.DIRECTORY_TYPE, 0777);
- }
- this.cacheFile.appendRelativePath("feed");
- } catch(e){ this.notifier.notifyObservers(null, "yahoo-feed-error", "400: "+ e); }
- this.loadFeed(true);
- this.loaded = true;
- }
- },
- run : function(){
- this.load(false);
- },
- buildFeedUrl : function(type){
- var param;
- var url = "";
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- var fnum = 2;
- var fver = 4;
- var time = (new Date().getTime());
- var cc = (prefs.prefHasUserValue("yahoo.installer.country")) ? prefs.getCharPref("yahoo.installer.country") +"." : "us.";
- var pc = (prefs.prefHasUserValue("yahoo.installer.pc")) ? prefs.getCharPref("yahoo.installer.pc") : "";
- var tid = (prefs.prefHasUserValue("yahoo.installer.toolbarID")) ? prefs.getCharPref("yahoo.installer.toolbarID") : "";
- var cid = (prefs.prefHasUserValue("yahoo.installer.corpID")) ? prefs.getCharPref("yahoo.installer.corpID") : "";
- var lang = (prefs.prefHasUserValue("yahoo.installer.language")) ? prefs.getCharPref("yahoo.installer.language") : cc;
- var cver = (prefs.prefHasUserValue("yahoo.installer.version")) ? prefs.getCharPref("yahoo.installer.version") : "1.1.0";
- if(!this.isGuest && (param = this.params.get("lang")) != null){
- lang = param.func;
- }
- if(tid == ""){
- tid = "none";
- }
- if(cver != ""){
- cver = cver.split(".");
- if(cver.length > 3){
- cver.length = 3;
- }
- cver = cver.join("_");
- }
- if(type == 0){
- url = "http:\/\/"+ cc +"update2.toolbar.yahoo.com"+
- "/slv/v"+ fver +
- "/"+ fnum +".html"+
- "?&.pc="+ pc +
- "&t="+ time +
- "&.ta=cg"+ tid +
- ",cc"+ cid +
- ",ci"+ lang +
- ",cv"+ cver +
- ",cp"+ pc +
- ",cbm";
- }
- else{
- url = "http:\/\/"+ cc +"update.companion.yahoo.com"+
- "/slv/v"+ fver +
- "/not?v="+ cver +
- "&t="+ time +
- "&.ta=cg"+ tid +
- ",cc"+ cid +
- ",ci"+ lang +
- ",cv"+ cver;
- }
- return url;
- },
- loadFeed : function(async){
- var cookies;
- try{
- this.loading = true;
- this.loadingAlerts = false;
- this.isGuest = true;
- cookies = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager2);
- cookies = cookies.enumerator;
- while(cookies.hasMoreElements()) {
- var cookie = cookies.getNext().QueryInterface(Components.interfaces.nsICookie);
- if(cookie.host == ".yahoo.com" && cookie.name == "Y") {
- if(cookie.value != null &&
- (cookie.value.search(/l=[^&]/) > -1 || cookie.value.indexOf("np=1") > -1)){
- this.isGuest = false;
- }
- break;
- }
- }
- this.FEED_URL = this.buildFeedUrl(0);
- var iosvc = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var channel = iosvc.newChannel(this.FEED_URL, 0, null);
- channel.asyncOpen(this, null);
- } catch(e){ this.notifier.notifyObservers(null, "yahoo-feed-error", "405: "+ e); }
- cookies = null;
- this.loading = false;
- },
- loadCachedFeed : function(){
- var inStream, handle;
- try{
- this.loadedType = this.CACHE_LOADED;
- this.notifier.notifyObservers(null, "yahoo-feed-loading-cached", null);
- if(this.cacheFile.exists()){
- inStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
- inStream.init(this.cacheFile, 0x01, 0666, 0);
- handle = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
- handle.init(inStream);
- var size = 0;
- this.raw = "";
- while(size = inStream.available()) {
- this.raw += handle.read(size);
- this.size += size;
- }
- }
- else{
- this.notifier.notifyObservers(null, "yahoo-feed-error", "409: No cache file");
- return false;
- }
- if(this.size < 0){
- this.notifier.notifyObservers(null, "yahoo-feed-error", "408: Empty cache");
- return false;
- }
- this.processFeed();
- this.notifier.notifyObservers(this, "yahoo-feed-updated", null);
- }catch(e){
- this.notifier.notifyObservers(null, "yahoo-feed-error", "407: "+ e);
- }
- if(handle){
- handle.close();
- }
- if(inStream){
- inStream.close();
- }
- },
- onStartRequest: function(request, context) {
- this.size = 0;
- this.raw = "";
- },
- onDataAvailable: function(request, context, inputStream, offset, count) {
- if(this.stream == null){
- this.stream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
- }
- this.stream.init(inputStream);
- this.raw += this.stream.read(count);
- },
- onStopRequest: function(request, context, statusCode) {
- var http;
- try{
- if(this.stream != null){
- try{ this.stream.close(); }catch(e){}
- this.stream = null;
- }
- http = request.QueryInterface(Components.interfaces.nsIHttpChannel);
- if(this.raw == "" || http.status != 0) {
- this.loadCachedFeed();
- return;
- }
- this.size = this.raw.length;
- this.processFeed();
- this.cacheFeed();
- this.loadedType = this.LIVE_LOADED;
- this.notifier.notifyObservers(this, "yahoo-feed-updated", null);
- if(this.domBuilder.bm2Feed){
- this.processBM2();
- }
- else{
- }
- try{
- if(this.timer == null){
- var delay = 1000 * 60 * 7;
- var processor = this;
- var callback = {
- notify : function(timer){ processor.retrieveAlerts(); }
- };
- this.timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
- this.timer.initWithCallback(callback, delay, this.timer.TYPE_REPEATING_PRECISE);
- }
- } catch(e){
- this.notifier.notifyObservers(null, "yahoo-feed-warning", "405: "+ e);
- }
- try{
- if(this.bm2timer == null){
- var delay = 1000 * 60 * 60;
- var processor = this;
- var callback = {
- notify : function(bm2timer){
- var str = processor.domBuilder.getBM2UsageString();
- if(str.length > 0) {
- processor.processBM2();
- }
- }
- };
- this.bm2timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
- this.bm2timer.initWithCallback(callback, delay, this.bm2timer.TYPE_REPEATING_PRECISE);
- }
- } catch(e){
- this.notifier.notifyObservers(null, "yahoo-feed-warning", "405: "+ e);
- }
- } catch(e) {
- this.loadedType = this.NOT_LOADED;
- this.notifier.notifyObservers(null, "yahoo-feed-error", "403: "+ e);
- }
- http = null;
- request = null;
- context = null;
- this.loading = false;
- },
- cacheFeed : function(){
- if(this.raw != null && this.raw != ""){
- try{
- if(this.cacheFile != null && this.isGuest){
- if(!this.cacheFile.exists()){
- this.cacheFile.create(this.cacheFile.NORMAL_FILE_TYPE, 0666);
- }
- var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
- out.init(this.cacheFile, 0x20 | 0x02, 00666, null);
- out.write(this.raw, this.raw.length);
- out.flush();
- out.close();
- }
- } catch(e){ this.notifier.notifyObservers(null, "yahoo-feed-error", "440: "+ e); }
- }
- },
- clear : function(){
- this.domBuilder.clear();
- this.params.clear();
- this.values.clear();
- },
- processFeed : function(){
- if(this.raw != null && this.raw != ""){
- this.clear();
- var pos = 0;
- while(pos < this.size){
- pos = this.readNextNode(null, pos);
- }
- pos = null;
- this.loads++;
- }
- else{
- throw "No feed data";
- }
- },
- readNextNode : function(parent, pos){
- try{
- var first = this.raw.charAt(pos++);
- if(first != this.code[0x14] && first != this.code[0x16]){
- return pos;
- }
- var ch;
- var num = 0;
- var param = "";
- var params = new Array();
- while(pos < this.size){
- ch = this.raw[pos++];
- if(first == this.code[0x16]){
- if(num == 0){
- params[0] = "";
- num++;
- }
- else if(num == 2){
- params[2] = this.code[0x16];
- params[3] = "";
- num += 2;
- }
- else if(num == 10){
- params[10] = "";
- num++;
- }
- }
- if(ch == this.code[0x19]){
- params[num++] = param;
- param = "";
- break;
- }
- else if(ch == this.code[0x18]){
- params[num++] = param;
- param = "";
- }
- else{
- param += ch;
- }
- }
- if(num > 1){
- var node = Components.classes["@yahoo.com/feed/node;1"].createInstance(Components.interfaces.nsIYahooFeedNode);
- node.name = params[1];
- node.type = params[2].charCodeAt(0);
- if(node.type == node.VALUE_TYPE){
- this.values.addString(node.name, params[3]);
- node = null;
- }
- else{
- node.icon = params[3];
- node.func = params[4];
- if(node.func != ""){
- node.func = node.func.replace(/,/g, "%2C");
- var func = node.func.split(this.code[0x01]);
- node.func = func.join(",");
- if(func.length > 1){
- node.funcNum = parseInt(func[1], 10);
- if(func.length > 2){
- node.funcTracking = func[2];
- }
- if(func.length > 3){
- func.splice(0,3);
- node.funcUrl = func.join(",");
- }
- }
- else if(func.length == 1){
- node.funcNum = -1;
- node.funcUrl = func[0];
- }
- func = null;
- }
- if(node.type == node.PARAM_TYPE && node.name == "lang" && isFinite(node.icon)){
- this.uniconvert.charset = this.charsets[node.icon];
- this.raw = this.uniconvert.ConvertToUnicode(this.raw);
- }
- if(node.type != node.PARAM_TYPE){
- this.cacheIcon(node);
- }
- if(node.type == 0x05){
- node.type = node.BUTTONMENU_TYPE
- }
- else if( node.name == "-" || node.icon == "vsep" || node.name == "spr" || node.name == "sep"){
- node.type = node.SEPARATOR_TYPE;
- }
- var styles = 0;
- if(num > 5 && params[5] != ""){
- styles = params[5];
- }
- var extStyles = 0;
- if(num > 7 && params[7] != ""){
- extStyles = params[7];
- }
- this.processStyles(node, styles, extStyles);
- if(num > 12 && params[12] != ""){
- params[12] = params[12].split("&");
- for(var i = 0; i < params[12].length; i++){
- params[12][i] = params[12][i].split("=");
- if(params[12][i].length > 1){
- if(params[12][i][0] == "icov"){
- node.icon = params[12][i][1];
- this.cacheIcon(node);
- }
- else if(params[12][i][0] == "id"){
- node.id = params[12][i][1].replace(/g_/g, "_");
- }
- params[12][i][1] = params[12][i][1].replace(/\\/g, "\\\\");
- params[12][i][1] = params[12][i][1].replace(/'/g, "\\'");
- // Add to JSON object
- params[12][i] = "'"+ params[12][i][0] +"':'"+ params[12][i][1] +"'";
- }
- else{
- params[12][i] = "'"+ params[12][i][0] +"':true";
- }
- node.hash += ((i > 0) ? ",": "") + params[12][i];
- }
- }
- // Add namespace to ID
- if(node.id != null){
- node.id = ((parent != null && parent.id) ? parent.id : "yahoo-toolbar") +"-"+ node.id;
- }
- // REVIEW NOTE: explains 'added'
- var added = false;
- // Add node to array
- if(parent == null && node.type == node.PARAM_TYPE){
- this.params.add(node.name, node);
- if(node.id != "yahoo-toolbar-acs"){
- added = true;
- }
- }
- else if(parent != null && parent instanceof Components.interfaces.nsIYahooFeedNode){
- parent.addChild(node);
- }
- // Reassign parent to DOM Node
- if(parent != null && parent.domToolbar != null){
- parent = parent.domToolbar;
- }
- else if(parent instanceof Components.interfaces.nsIYahooFeedNode){
- parent = null;
- }
- // Child nodes
- while(pos < this.size && this.raw[pos] != this.code[0x15] && this.raw[pos] != this.code[0x17]){
- // Add node to DOM
- if(added == false && node != null){
- // Make this a menu (since it's not explicitly set in feed)
- switch(node.type){
- case node.BUTTON_TYPE:
- node.type = node.BUTTONMENU_TYPE;
- break;
- case node.MENUITEM_TYPE:
- node.type = node.MENU_TYPE;
- break;
- }
- node.domToolbar = this.domBuilder.addNode(node, parent);
- added = true;
- }
- // Recurse into child
- pos = this.readNextNode(node, pos);
- }
- // Create DOM node -- if haven't already
- // - ignore if it's a menu, because if it hasn't been added already, then there aren't any children
- if(added == false && node.type != node.MENU_TYPE && node.type != node.BUTTONMENU_TYPE){
- node.domToolbar = this.domBuilder.addNode(node, parent);
- }
- }
- pos++;
- if(node != null && node.type != node.PARAM_TYPE){
- node.destroy();
- }
- node = null;
- ch = null;
- num = null;
- first = null;
- param = null;
- params = null;
- }
- } catch(e){
- this.notifier.notifyObservers(null, "yahoo-feed-warning", "420: "+ e);
- }
- parent = null;
- return pos;
- },
- /**
- * Process the feed style codes
- * @param {nsIYahooFeedNode} node The feed node to with style data
- * @param {int} styles The styles flag
- * @param {int} extStyles The extended styles flag
- */
- processStyles : function(node, styles, extStyles){
- var bit = 0;
- var nodeStyles = ",";
- var stdBits = this.styles.std;
- var extBits = this.styles.ext;
- try{
- // No styles
- if(styles == 0 && extStyles == 0){
- return;
- }
- // Standard styles
- var key;
- if(styles > 0){
- for(key in this.styles.std){
- if(styles & key){
- nodeStyles += stdBits[key] +",";
- }
- }
- }
- // Extended
- var key;
- if(extStyles > 0){
- for(key in extBits){
- if(extStyles & key){
- nodeStyles += extBits[key] +",";
- }
- }
- }
- node.styles = nodeStyles;
- } catch(e) {
- }
- },
- /**
- * Cache the node's icon
- * @param {nsIYahooFeedNode} node The node with the icon to cache
- */
- cacheIcon : function(node){
- var path = "http:\/\/us.i1.yimg.com/us.yimg.com/i/tb/iconsgif/";
- var icon = node.icon;
- if(icon == ""){
- return "";
- }
- // Chrome URL
- if(icon.indexOf(".") < 0){
- node.icon = "chrome:\/\/ytoolbar/skin/"+ icon + ".gif";
- }
- // External Icon
- else{
- icon = icon.replace(/\.bmp$/i, ".gif");
- path += icon;
- node.icon = path;
- }
- },
- /**
- * Get Alerts (i.e new mail) from the server for a logged-in user.
- * When the alert feed has been read, the <b>yahoo-feed-alert</b> notification will be sent.
- */
- retrieveAlerts : function(){
- try{
- // User not logged in
- if(this.isGuest){
- return;
- }
- this.loadingAlerts = true;
- var url = this.buildFeedUrl(1);
- var processor = this;
- // Make request
- var iosvc = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var channel = iosvc.newChannel(url, 0, null);
- var channelListener = {
- stream : null,
- onStartRequest: function(request, context) {
- processor.raw = "";
- },
- onDataAvailable: function(request, context, inputStream, offset, count) {
- if(this.stream == null){
- this.stream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
- }
- this.stream.init(inputStream);
- processor.raw += this.stream.read(count);
- },
- // Process returned feed
- onStopRequest: function(request, context, statusCode) {
- try{
- if(this.stream != null){
- this.stream.close();
- }
- request.QueryInterface(Components.interfaces.nsIHttpChannel);
- // load error
- if(processor.raw == "" || request.status != 0) {
- return;
- }
- // Encode to utf-8
- if(processor.uniconvert.charset != "utf-8"){
- processor.raw = processor.uniconvert.ConvertToUnicode(processor.raw);
- }
- // Empty alerts
- while(processor.domBuilder.alerts.firstChild){
- processor.domBuilder.alerts.removeChild(processor.domBuilder.alerts.firstChild);
- }
- // Get alert nodes from feed
- var pos = 0;
- var len = processor.raw.length;
- while(processor.loadingAlerts && pos < len){
- pos = processor.readNextNode(processor.domBuilder.alerts, pos);
- }
- processor.loadingAlerts = false;
- // Notify toolbar of new alerts
- processor.notifier.notifyObservers(null, "yahoo-feed-alerts-updated", processor.domBuilder.alerts.childNodes.length);
- } catch(e) {
- processor.notifier.notifyObservers(null, "yahoo-feed-warning", "451: "+ e);
- }
- this.stream = null;
- processor = null
- }
- };
- channel.asyncOpen(channelListener, null);
- } catch(e){
- processor.notifier.notifyObservers(null, "yahoo-feed-warning", "451: "+ e);
- }
- },
- /**
- * Process and build the Bookmarks 2.0 list
- */
- processBM2 : function(){
- try{
- // No feed URL
- if(!this.domBuilder.bm2Feed || this.domBuilder.bm2Feed == ""){
- return;
- }
- var self = this;
- var iosvc = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var bm2url = this.domBuilder.bm2Feed;
- var str = this.domBuilder.getBM2UsageString();
- if(str.length > 0) {
- bm2url += "&docids=" + str;
- this.domBuilder.clearBM2Usage();
- }
- var channel = iosvc.newChannel(bm2url, 0, null);
- var listen = {
- stream : null,
- xml : "",
- onStartRequest: function(request, context) {
- this.xml = "";
- },
- onDataAvailable: function(request, context, inputStream, offset, count) {
- if(this.stream == null){
- this.stream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
- }
- this.stream.init(inputStream);
- this.xml += this.stream.read(count);
- },
- onStopRequest: function(request, context, statusCode) {
- var http;
- try{
- if(this.stream != null){
- // Try to close if initialized
- try{ this.stream.close(); }catch(e){}
- this.stream = null;
- }
- // REVIEW NOTE: what is in statusCode ^
- http = request.QueryInterface(Components.interfaces.nsIHttpChannel);
- // Build bookmarks
- if(this.xml != "" && http.status == 0) {
- var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
- var doc = parser.parseFromString(this.xml, "text/xml");
- var root = doc.getElementsByTagName("outline");
- if(root.length > 0){
- self.domBuilder.clearBM2();
- self.domBuilder.buildBM2(root[0], null);
- self.notifier.notifyObservers(null, "yahoo-feed-bookmarks-updated", null);
- self.debug("Nodes: "+ self.domBuilder.bookmarks.childNodes.length);
- }
- }
- } catch(e){
- self.debug("ERROR in processBM2.onStopRequest(): "+ e);
- }
- }
- }
- channel.asyncOpen(listen, null);
- } catch(e){
- }
- },
- /**
- * Uses the DebugLogger Mozmonkey extension to log messages (Tools -> DebugLogger)
- * @private
- */
- debug : function(msg){
- if(typeof(Components.interfaces.nsIDebugLoggerManager) != 'undefined'){
- logMngr = Components.classes["@mozmonkey.com/debuglogger/manager;1"].getService(Components.interfaces.nsIDebugLoggerManager);
- //var d = new Date();
- //var time = d.getHours() +":"+ d.getMinutes() +":"+ d.getSeconds();
- logger = logMngr.registerLogger("yfeedtest");
- logger.log(3, msg);
- }
- },
- /* DO NOT CHANGE */
- QueryInterface: function (iid) {
- if(!iid.equals(Components.interfaces.nsIYahooFeedProcessor) && !iid.equals(Components.interfaces.nsISupports) && !iid.equals(Components.interfaces.nsIRunnable))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
- };
- /**
- * DO NOT CHANGE THIS OBJECT
- * @private
- */
- function NSGetModule(compMgr, fileSpec) {
- return {
- myCID : Components.ID("{4138788A-68DF-4cb5-B6F9-E50DE9C70708}"),
- myProgID : "@yahoo.com/feed/processor;1",
- firstTime : true,
- registerSelf : function (compMgr, fileSpec, location, type) {
- if (this.firstTime) {
- this.firstTime = false;
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
- }
- compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(this.myCID, "Yahoo! Feed Processor", this.myProgID, fileSpec, location, type);
- },
- getClassObject : function (compMgr, cid, iid) {
- if (!cid.equals(this.myCID)) throw Components.results.NS_ERROR_NO_INTERFACE;
- if (!iid.equals(Components.interfaces.nsIFactory)) throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
- return this.myFactory;
- },
- myFactory : {
- createInstance : function (outer, iid) {
- if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new nsIYahooFeedProcessor()).QueryInterface(iid);
- }
- },
- canUnload : function(compMgr) { return true; }
- };
- }
-